package com.xunlai.infra.permission.business.controller;

import com.xunlai.infra.permission.business.service.InvitationCodeService;
import com.xunlai.infra.permission.business.vo.invitation.InvitationCodeCreateVo;
import com.xunlai.infra.permission.business.vo.invitation.InvitationCodeListVo;
import com.xunlai.infra.permission.business.vo.invitation.InvitationUpdateVo;
import com.xunlai.infra.permission.common.exception.PermissionBusinessException;
import com.xunlai.infra.permission.common.vo.BasePageRespVo;
import com.xunlai.infra.permission.common.vo.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liang
 * @date 8/21/23 10:43 PM
 */
@RestController
@RequestMapping("travel/manage/invitationCode")
public class InvitationCodeManageController {

    private InvitationCodeService invitationCodeService;


    @PostMapping("create")
    public BaseResponse<Long> createInvitationCode(@RequestBody InvitationCodeCreateVo invitationCodeCreateVo){
        try {
            return BaseResponse.success(invitationCodeService.createInvitationCode(invitationCodeCreateVo));
        } catch (PermissionBusinessException e) {
            return BaseResponse.error(e.getCode(), e.getMsg());
        }
    }

    @PutMapping("update/{id}")
    public BaseResponse<Void> bindInviterAccount(@PathVariable Long id ,@RequestBody InvitationUpdateVo invitationUpdateVo){
        invitationCodeService.bindInviterAccount(id,invitationUpdateVo);
        return BaseResponse.success();
    }

    @GetMapping("list")
    public BaseResponse<BasePageRespVo<InvitationCodeListVo>> listInvitationCode(
            @RequestParam(required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(required = false,defaultValue = "10")Integer pageSize) {
        return BaseResponse.success(invitationCodeService.listInvitationCode(pageNum,pageSize));
    }



    @Autowired
    public void setInvitationCodeService(InvitationCodeService invitationCodeService) {
        this.invitationCodeService = invitationCodeService;
    }
}
